#if NO_CMDLINE
#else

#ifndef  _CMDLINE_H_
#define  _CMDLINE_H_

#ifdef _cplusplus
extern "c"{
#endif


#include "Typedef.h"


#define	ENTER_KEY	0x0d
#define	BACK_KEY	0x08
#define BEEP_KEY	0x07
#define UP_KEY		0x41
#define DOWN_KEY	0x42
#define RIGHT_KEY	0x43
#define LEFT_KEY	0x44
#define HOME_KEY	0x48
#define END_KEY		0x4b
#define	ESC_KEY		0x1b
#define	EOF_KEY		0x1a
#define CANCEL_KEY  0x03
#define EOT_KEY     0x04

#define MAX_UART_COMLINE 	(uint8)30
#define MAX_FUNCTION_NAME	(uint8)30
#define MAX_STRING_LEN		(uint8)30
#define MAX_ARGS_LEN		(uint8)12
enum
{
	  PARSE_NAME = 0
	, PARSE_ARGS1
	, PARSE_ARGS2
	, PARSE_ARGS3
	, PARSE_ARGS4
	, PARSE_END
};

//Error code
enum
{
	 EC_OK = 0
	,EC_NAME
	,EC_ARGS1
	,EC_ARGS2
	,EC_ARGS3
	,EC_ARGS4
	,EC_TOO_MANY_PARAM
	,EC_TOO_MANY_STRING_PARAM
};

#define MAX_STRING_ARGS		(PARSE_END - 1)
struct _CmdLine;
typedef struct _CmdParser
{
	uint8 m_ErrorCode:3;
	uint8 m_isEcho:1;
	uint8 m_stringArgsCount:3;
	uint8 m_isParseString:1;
	
	uint8 m_State:3;
	uint8 m_MaxLen:5;
	
	uint8 m_ArgsCount:3;
	uint8 m_nIndex:5;
	
	uint8 m_Cmd[MAX_FUNCTION_NAME+1];
	uint32 m_Args[PARSE_END - 1];
	uint8 m_String[MAX_STRING_ARGS][MAX_STRING_LEN+1];
	uint8 m_NumStr[MAX_ARGS_LEN+1];
	uint8* m_pData;

	const struct _CmdLine* m_pCmdTable;	//Point to a CmdLine array
	uint8 m_CmdTableCount;		//Nunber of CmdLine array
}CmdParser;

typedef int (*CmdLineProcFun)(CmdParser* pCmdParser);
typedef struct _CmdLine
{
	const char* m_pCmdParser;
	CmdLineProcFun CmdProc;
	const char* m_pHelp;
}CmdLine;


Bool Str_toUl(const uint8 *s, uint32* pUint32);
void CmdParser_Init(CmdParser* pCmdParser, const CmdLine* pCmdTable, uint8 cmdTableCount, Bool isEcho);
int CmdParser_Parse(CmdParser* pCmdParser, const uint8* str, uint8 len);
void CmdParser_Excute(CmdParser* pCmdParser);
void CmdParser_Reset(CmdParser* pCmdParser);

#ifdef _cplusplus
}
#endif

#endif 

#endif //#if NO_CMDLINE



